/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.quality4spl.fm.cvm.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.quality4spl.fm.cvm.CvmPackage;
import org.quality4spl.fm.cvm.UserAttributeValue;
import org.quality4spl.fm.cvm.VariabilityModelElement;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Variability Model Element</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariabilityModelElementImpl#getId <em>Id</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariabilityModelElementImpl#getAuthorName <em>Author Name</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.VariabilityModelElementImpl#getUserAttributeValues <em>User Attribute Values</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class VariabilityModelElementImpl extends CVMElementImpl implements VariabilityModelElement {
	/**
	 * The default value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected static final String ID_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected String id = ID_EDEFAULT;

	/**
	 * The default value of the '{@link #getAuthorName() <em>Author Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAuthorName()
	 * @generated
	 * @ordered
	 */
	protected static final String AUTHOR_NAME_EDEFAULT = "";

	/**
	 * The cached value of the '{@link #getAuthorName() <em>Author Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAuthorName()
	 * @generated
	 * @ordered
	 */
	protected String authorName = AUTHOR_NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getUserAttributeValues() <em>User Attribute Values</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUserAttributeValues()
	 * @generated
	 * @ordered
	 */
	protected EList<UserAttributeValue> userAttributeValues;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected VariabilityModelElementImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CvmPackage.Literals.VARIABILITY_MODEL_ELEMENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getId() {
		return id;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setId(String newId) {
		String oldId = id;
		id = newId;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.VARIABILITY_MODEL_ELEMENT__ID, oldId, id));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getAuthorName() {
		return authorName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAuthorName(String newAuthorName) {
		String oldAuthorName = authorName;
		authorName = newAuthorName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.VARIABILITY_MODEL_ELEMENT__AUTHOR_NAME, oldAuthorName, authorName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<UserAttributeValue> getUserAttributeValues() {
		if (userAttributeValues == null) {
			userAttributeValues = new EObjectContainmentWithInverseEList<UserAttributeValue>(UserAttributeValue.class, this, CvmPackage.VARIABILITY_MODEL_ELEMENT__USER_ATTRIBUTE_VALUES, CvmPackage.USER_ATTRIBUTE_VALUE__ELEMENT);
		}
		return userAttributeValues;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__USER_ATTRIBUTE_VALUES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getUserAttributeValues()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__USER_ATTRIBUTE_VALUES:
				return ((InternalEList<?>)getUserAttributeValues()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__ID:
				return getId();
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__AUTHOR_NAME:
				return getAuthorName();
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__USER_ATTRIBUTE_VALUES:
				return getUserAttributeValues();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__ID:
				setId((String)newValue);
				return;
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__AUTHOR_NAME:
				setAuthorName((String)newValue);
				return;
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__USER_ATTRIBUTE_VALUES:
				getUserAttributeValues().clear();
				getUserAttributeValues().addAll((Collection<? extends UserAttributeValue>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__ID:
				setId(ID_EDEFAULT);
				return;
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__AUTHOR_NAME:
				setAuthorName(AUTHOR_NAME_EDEFAULT);
				return;
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__USER_ATTRIBUTE_VALUES:
				getUserAttributeValues().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__ID:
				return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id);
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__AUTHOR_NAME:
				return AUTHOR_NAME_EDEFAULT == null ? authorName != null : !AUTHOR_NAME_EDEFAULT.equals(authorName);
			case CvmPackage.VARIABILITY_MODEL_ELEMENT__USER_ATTRIBUTE_VALUES:
				return userAttributeValues != null && !userAttributeValues.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (id: ");
		result.append(id);
		result.append(", authorName: ");
		result.append(authorName);
		result.append(')');
		return result.toString();
	}

} //VariabilityModelElementImpl
